package cn.xo68.demo.client.config;

import cn.xo68.boot.auth.core.common.AuthConstants;
import cn.xo68.boot.cache.common.CacheConfiguration;
import cn.xo68.boot.cache.common.CacheConfigurer;
import cn.xo68.boot.cache.common.CacheConstant;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * 缓存配置
 * @author wuxie
 * @version 2019-11-25
 */
@Configuration
public class WxCacheConfigurer implements CacheConfigurer {



    @Override
    public void addConfig(List<CacheConfiguration> configurations) {

        //用户信息
        CacheConfiguration clientCacheConfiguration= CacheConfiguration.create(AuthConstants.CACHE_NAME_CLIENT_USERINFO)
                .usePrefix(true)
                .cachePrefix(AuthConstants.CACHE_NAME_CLIENT_USERINFO+AuthConstants.SPLIT_COLON)
                .timeoutSeconds(120)
                .build();
        configurations.add(clientCacheConfiguration);

        //客户端资源
        CacheConfiguration resourceCacheConfiguration= CacheConfiguration.create(AuthConstants.CACHE_NAME_CLIENT_RESOURCE)
                .usePrefix(true)
                .cachePrefix(AuthConstants.CACHE_NAME_CLIENT_RESOURCE+AuthConstants.SPLIT_COLON)
                .timeoutSeconds(120)
                .build();
        configurations.add(resourceCacheConfiguration);



    }

    @Override
    public CacheConfiguration getCacheDefault() {
        //默认保存30分钟
        CacheConfiguration cacheConfiguration= CacheConfiguration.create(CacheConstant.CACHE_NAME_DEFAULT)
                .usePrefix(true)
                .cachePrefix(CacheConstant.CACHE_PREFIX_DEFAULT)
                .timeoutSeconds(60*30)
                .build();
        return cacheConfiguration;
    }
}
